#!/bin/bash
PKGNAME="libwwt"
VERSION="3.05a"
REL=1
ARCH="amd64"
MAINTAINER="CYBERDEViL <cyberdevil@notabug.org>"
DESC="lib build from wit's wwt"
URL="https://notabug.org/cyberdevil/libwwt"
DEPENDS="libncurses-dev, openssl, libc6, libmhash2, libbz2-1.0, zlib1g"


SRCDIR=$(realpath "libwwt")
PKGDIR=$(realpath "libwwt-${VERSION}-${REL}_${ARCH}")


get_sources() {
  if [[ ! -d libwwt ]]; then
    git clone --recurse-submodules "${URL}" "${PKGNAME}"
  fi
}

build() {
  cd "${SRCDIR}"
  make shared
}

package() {
  cd "${SRCDIR}"
  make DESTDIR="${PKGDIR}/" PREFIX="usr/" install
}


# Make sure the pkg dir is fresh
if [[ -d "${PKGDIR}" ]]; then
  rm -rf "${PKGDIR}"
fi
mkdir "${PKGDIR}"

# Get the sources
get_sources

# Build the sources
build

# Package
package


mkdir "${PKGDIR}/DEBIAN"
echo "Package: ${PKGNAME}
Version: ${VERSION}
Maintainer: ${MAINTAINER}
Depends: ${DEPENDS}
Architecture: ${ARCH}
Homepage: ${URL}
Description: ${DESC}" \
> "${PKGDIR}/DEBIAN/control"

dpkg --build "${PKGDIR}"
